package com.itjeffrey.autocode.controller;

import com.itjeffrey.autocode.bo.RoleInfoTbBO;
import com.itjeffrey.autocode.bo.req.IsEnableBO;
import com.itjeffrey.autocode.common.Result;
import com.itjeffrey.autocode.service.RoleInfoTbService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 控制器类
 * @author: admin
 * @date: 2021-03-28 12:26:46
 */
@RestController
@RequestMapping("/role/info")
public class RoleInfoTbController {

    @Resource
    private RoleInfoTbService roleInfoTbService;

    /**
     * 新增角色
     * @param roleInfoTbBO
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Result> add(@RequestBody @Valid RoleInfoTbBO roleInfoTbBO){
        return ResponseEntity.ok(roleInfoTbService.add(roleInfoTbBO));
    }

    /**
     * 修改角色
     * @param roleInfoTbBO
     * @return
     */
    @PostMapping("/mod")
    public ResponseEntity<Result> mod(@RequestBody @Valid RoleInfoTbBO roleInfoTbBO){
        return ResponseEntity.ok(roleInfoTbService.mod(roleInfoTbBO));
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResponseEntity<Result> delete(@PathVariable("id") String id){
        return ResponseEntity.ok(roleInfoTbService.delete(id));
    }

    /**
     * 查询角色列表
     * @param roleInfoTbBO
     * @return
     */
    @PostMapping("/query")
    public ResponseEntity<Result> queryList(@RequestBody @Valid RoleInfoTbBO roleInfoTbBO){
        return ResponseEntity.ok(roleInfoTbService.queryList(roleInfoTbBO));
    }

    /**
     * 查询角色列表，不包括本身角色
     * @param roleInfoTbBO
     * @return
     */
    @PostMapping("/queryRolesOutOfSelfRole")
    public ResponseEntity<Result> queryRolesOutOfSelfRole(@RequestBody @Valid RoleInfoTbBO roleInfoTbBO){
        return ResponseEntity.ok(roleInfoTbService.queryRolesOutOfSelfRole(roleInfoTbBO));
    }

    @RequestMapping("/query/{id}")
    public ResponseEntity<Result> queryOne(@PathVariable("id") Integer roleId){
        return ResponseEntity.ok(roleInfoTbService.queryOne(roleId));
    }

    /**
     * 角色是否启用
     * @param isEnableBO
     * @return
     */
    @PostMapping("/isEnableRole")
    public ResponseEntity<Result> isEnableRole(@RequestBody IsEnableBO isEnableBO){
        return ResponseEntity.ok(roleInfoTbService.isEnableRole(isEnableBO));
    }

}